layui.use(['form', 'layer'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;

    form.on("submit(addRoleBase)", function (data) {
        //弹出loading
        var index = top.layer.msg('数据保存中，请稍候...', {icon: 16, time: false, shade: 0.8});
        $.ajax({
            url: "/role/base/save",
            data: data.field,
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            async: false,
            success: function (res) {
                if (res.data) {
                    var _index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(_index);
                    layer.close(index);
                    layer.msg("保存成功！");
                } else {
                    layer.msg(res.msg);
                }
            },
            error: function (res) {
                layer.msg("添加失败！");
            }
        });
        parent.location.reload();
        return false;
    });

    $(".cancel").click(function () {
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        parent.layer.close(index);
    })
});